package com.cdxy.controller;

import com.cdxy.aop.ForceLogin;
import com.cdxy.biz.process.IIndexBizProcess;
import com.cdxy.model.dto.base.controller.BaseController;
import com.cdxy.model.dto.base.resp.ApiResponse;
import com.cdxy.model.dto.req.HomeIndexReq;
import com.cdxy.model.dto.req.HomeIndexSceneReq;
import com.cdxy.model.dto.req.SearchRecommendReq;
import com.cdxy.model.dto.req.UserWithLoginReq;
import com.cdxy.model.dto.req.app.AppMddReq;
import com.cdxy.model.dto.resp.BasicUserInfoResp;
import com.cdxy.model.dto.resp.HomeIndexResp;
import com.cdxy.model.dto.resp.HomeIndexSceneResp;
import com.cdxy.model.dto.resp.app.AppMddResp;
import com.cdxy.model.dto.resp.app.AppSearchRecommendResp;
import com.cdxy.util.AxUidUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: tangy
 * @Date: 2020/3/17 11:35
 */
@RestController
@Api(value = "页面初始化", tags = "页面初始化")
@RequestMapping("/index")
public class IndexController extends BaseController {

    @Autowired
    private IIndexBizProcess indexBizProcess;

    @Autowired
    private AxUidUtil axUidUtil;

    @GetMapping("/homeIndex")
    @ApiOperation(value = "首页数据渲染", notes = "首页")
    public ApiResponse<HomeIndexResp> homeIndex(@Validated HomeIndexReq homeIndexReq) {
        return successApiResponse(indexBizProcess.homeIndex(homeIndexReq));
    }

    @GetMapping("/homeIndexScene")
    @ApiOperation(value = "首页景点数据", notes = "首页")
    public ApiResponse<HomeIndexSceneResp> homeIndexScene(@Validated HomeIndexSceneReq homeIndexSceneReq) {
        homeIndexSceneReq.setAxUid(axUidUtil.getAxUidNotForce());
        return successApiResponse(indexBizProcess.homeIndexScene(homeIndexSceneReq));
    }

    @GetMapping("/mdd")
    @ApiOperation(value = "app 目的地", notes = "")
    public ApiResponse<AppMddResp> appMdd(@Validated AppMddReq appMddReq) {
        appMddReq.setAxUid(axUidUtil.getAxUidNotForce());
        return successApiResponse(indexBizProcess.appMdd(appMddReq));
    }

    @GetMapping("/searchRecommend")
    @ApiOperation(value = "搜索推荐", notes = "")
    public ApiResponse<AppSearchRecommendResp> searchRecommend(SearchRecommendReq searchRecommendReq) {
        return successApiResponse(indexBizProcess.appSearchRecommend(searchRecommendReq));
    }

    @GetMapping("/basicUserInfo")
    @ApiOperation(value = "用户个人信息", notes = "")
    @ForceLogin
    public ApiResponse<BasicUserInfoResp> basicUserInfo(@Validated UserWithLoginReq userWithLoginReq) {
        Integer axUid = axUidUtil.getAxUid();
        userWithLoginReq.setAxUid(axUid);
        return successApiResponse(indexBizProcess.basicUserInfo(userWithLoginReq));
    }
}
